package com.yz.jdd.base.activity;



import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import com.yz.jdd.R;


public class ToastDialog extends Dialog {

	private String msg;
	public ToastDialog(Context context, String msg) {
		super(context, R.style.Cate_Dialog);
		setContentView(R.layout.toast_dialog);
		this.msg=msg;
		if(!TextUtils.isEmpty(msg)){
			TextView msgText=(TextView) findViewById(R.id.loading_msg);

			msgText.setText(msg);
			msgText.setVisibility(View.VISIBLE);
		}
//		WindowManager m = context.getWindowManager();
//		Display d = m.getDefaultDisplay();
		LayoutParams p = getWindow().getAttributes();
		p.gravity= Gravity.CENTER;
		p.height = LayoutParams.WRAP_CONTENT;//(int) (d.getWidth() * 0.5);   //高度设置为屏幕的0.4
		p.width = LayoutParams.WRAP_CONTENT;//(int) (d.getWidth() * 0.85);    //宽度设置为屏幕的0.7
		getWindow().setAttributes(p);


	}
	
	public void setGroundNoBlack(){
		LayoutParams p = getWindow().getAttributes();
		p.flags &= ~LayoutParams.FLAG_DIM_BEHIND;
		p.gravity= Gravity.CENTER;
		getWindow().setAttributes(p); 
	}
	

	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode== KeyEvent.KEYCODE_BACK)
		{
			this.dismiss();
		}
		return super.onKeyDown(keyCode, event);
	}
	
}
